package Message;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class Message {
    private final String tag;//报文的类型
    private final String ID_src;//报文的源
    private final String ID_dst;//报文的目的ID
    private  Calendar TS;//报文时间戳
    private final int lifetime;//报文存活时间
    private final String content;//报文的内容
    private final String redu;//冗余位

    public void setTS(Calendar c)
    {
        TS=c;
    }
    public enum pos {
        tag,ID_src,ID_dst,lifetime,TS,content,redu;
    }
    public Message(String tag,String ID_src,String ID_dst,int lifetime,String content,String redu) {
        this.tag=tag;
        this.ID_dst=ID_dst;
        this.ID_src=ID_src;
        this.TS=Calendar.getInstance();
        this.lifetime=lifetime;
        this.content=content;
        this.redu=redu;

    }
    public String getID_src()
    {
        return ID_src;
    }
    public String getTag()
    {
        return tag;
    }
    public String getID_dst()
    {
        return ID_dst;
    }
    public int getLifetime()
    {
        return lifetime;
    }
    public String getContent()
    {
        return content;
    }
    public String getRedu()    {return redu;}

    public String toStr()
    {
        String c="|";
        String s_time="";
        if(TS.get(Calendar.DATE)<10)
        {
            s_time=s_time+"0"+TS.get(Calendar.DATE);

        }
        else
        {
            s_time=s_time+TS.get(Calendar.DATE);
        }
        if(TS.get(Calendar.HOUR)<10)
        {
            s_time=s_time+"0"+TS.get(Calendar.HOUR);
        }
        else
        {
            s_time=s_time+TS.get(Calendar.HOUR);
        }
        if(TS.get(Calendar.MINUTE)<10)
        {
            s_time=s_time+"0"+TS.get(Calendar.MINUTE);
        }
        else
        {
            s_time=s_time+TS.get(Calendar.MINUTE);
        }
        return this.tag+c+this.ID_src+c+ID_dst+c+lifetime+c+s_time+c+content+c+redu;
    }
}
